#include <string>
#include <iostream>

#include "ConnectionHandlerHTTP.hpp"
#include "Logger.hpp"

ConnectionHandlerHTTP::ConnectionHandlerHTTP() : ConnectionHandler() {
}

ConnectionHandlerHTTP::ConnectionHandlerHTTP(TCPConnection& connection) : ConnectionHandler(connection) {
}


void ConnectionHandlerHTTP::handle() {
	while (true) {
		std::string line;
		line = connection->getNextLine();
		if ((line == "\r") || (line == "")) break;
	}

	connection->sendLine("HTTP/1.0 200 OK\r\n");
	connection->sendLine("\r\n");
	connection->sendLine("<html>");
	connection->sendLine("	<body>\n");
	connection->sendLine("		<center><h1>Hello World</h1></center>\n");
	connection->sendLine("		<hr>\n");
	connection->sendLine("		<p>This is an http session, ");
	connection->sendLine(connection->getRemoteStr());
	connection->sendLine("</p>");
	connection->sendLine("	</body>\n");
	connection->sendLine("</html>");

	connection->close();
}

ConnectionHandlerHTTP::~ConnectionHandlerHTTP() {
}

